﻿using System;
using System.Reflection;

namespace GVPSys.sysbase
{
    public interface IInvocation
    {
        object Parameter { get; }
        MethodInfo Method { get; }
        SysCommandbase Target { get; }
        object Proceed();
    }

    internal class CommandInvocation : IInvocation
    {
        public object Parameter { get; private set; }
        public MethodInfo Method { get; private set; }
        public SysCommandbase Target { get; private set; }

        public CommandInvocation(MethodInfo method, object parameter, SysCommandbase target)
        {
            this.Parameter = parameter;
            this.Method = method;
            this.Target = target;
        }

        public object Proceed()
        {
            if (Method == null)
            {
                throw new Exception("Method is null");
            }
            if (Target == null)
            {
                throw new Exception("Target is null");
            }

            return Method.Invoke(Target, new[] { Parameter });
        }
    }
}
